package com.spring.demo6.eg8;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author vhans
 */
@Configuration
public class MainConfig10 {

    @Bean
    public Service1 service1() {
        return new Service1();
    }

    @Bean
    public Service2 service2() {
        return new Service2();
    }

    @Bean
    public Service3 service3() {
        // 1.@Bean结合硬编码的方式注入依赖
        // 2.@Bean也可以结合@Autowired，@Resource的方式注入依赖，直接在要通过@Bean注入的对象上在加上注解@Autowired或者@Resource即可
        Service3 service3 = new Service3();
        service3.setService1(this.service1());
        service3.setService2(this.service2());
        return service3;
    }
}
